package com.rephilo.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class UserClickProducer {

    @Autowired
    private KafkaTemplate<Integer, String> template;

    @PostMapping("/send")
    public String send(@RequestParam String userId,
                       @RequestParam String action) {
        Map<String, String> map = new HashMap<>();
        map.put("user_id", userId);
        map.put("act_time", String.valueOf(System.currentTimeMillis()));
        map.put("action", action);
        map.put("job_code", "9999");
        template.send("tp_individual", JSON.toJSONString(map));
        System.out.println("send successfully");
        return "success";
    }
}
